﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Data;
using Sirenix.OdinInspector;
# if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
# endif

namespace Gp.Scripts.Equip {
    public enum WeaponBasicType {
        [LabelText("近战类型")]
        Melee,
        
        [LabelText("远程类型")]
        Ranged,
        
        [LabelText("其他")]
        Misc,
    }
    
    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class WeaponTypeAttribute : Attribute {
        public string Name;
        public WeaponBasicType BasicType;
        
        public WeaponTypeAttribute(WeaponBasicType basicType, string name) {
            Name = name;
            BasicType = basicType;
        }
    }


# if UNITY_EDITOR
    public class WeaponTypeAttributeProcessor<T> : OdinAttributeProcessor<T> where T : BaseWeaponType {
        public override void ProcessSelfAttributes(InspectorProperty property, List<Attribute> attributes) {
            if (attributes.FirstOrDefault(i => i is WeaponTypeAttribute) is not WeaponTypeAttribute a) return;
            // if (attributes.Any(i => i is LabelTextAttribute))
            //     return;

            // string prefix = a.Type switch {
            //     WeaponType.Melee => "近战类型",
            //     WeaponType.Ranged => "远程类型",
            //     _ => "其他"
            // };
            // attributes.Add(new LabelTextAttribute(prefix + "/" + a.Name));

            attributes.Add(WeaponBasicType.Melee == a.BasicType
                ? new GUIColorAttribute(1, 0.75f, 0.75f)
                : new GUIColorAttribute(0.75f, 0.75f, 1f));
        }
    }
# endif
}